//是否为ios   if(isIos()) {}
function isIos() {
    return browser.versions.ios || browser.versions.iPhone || browser.versions.iPad
}

/////////**********客户端user-Agent验证************/////
/////////**********验证当前用户是通过什么浏览器或者什么类型的客户端访问该页面************/////
////***if(browser.versions.ios||browser.versions.iPhone||browser.versions.iPad){do what you want}*****/////

var browser = {
    versions: function () {
        var u = navigator.userAgent, app = navigator.appVersion;
        return { //移动终端浏览器版本信息
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 || u.indexOf("Adr"), //android终端或uc浏览器
            iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf('iPad') > -1, //是否iPad
            webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
        };
    }(),
    language: (navigator.browserLanguage || navigator.language).toLowerCase()
};

/////////**********验证当前用户是通过什么浏览器或者什么类型的客户端访问该页面************/////


/*淘口令*/
function popTao(img, title, content, tip) {
    var pop;
    if (!document.querySelector(".popw")) {
        var frag = document.createDocumentFragment(), html = "";
        var popw = document.createElement("div");
        frag.appendChild(popw);
        popw.className = "popw";
        html += "<div class='popwbg'></div>";
        html += "<div class='popwbox taobox'>";
        html += "<div class='taologo' style='background-image:url(" + img + ")'></div>";
        html += "<div class='taocon'>";
        html += "<div class='taotitle'>";
        html += "<div class='popwtitle taotitle'>长按虚线框内文字——>>全选——>>复制</div>";
        html += "<div class='popwcontent' id='taocontent'></div>";
        html += "</div></div>";
        html += "<div class='taotip'>提示：复制成功，打开淘宝将会自动跳转相应页面</div>";
        html += "<div class='taokaobox'>";
        if (!tip) {
            if (isIos()) {
                html += "<a href='javascript:;' class='taokao taokaocopy'><img src='../addons/bsht_tbk/res/images/ioscopy.png'></a>";
            } else {
                html += "<a href='javascript:;' class='taokao taokaocopy'><img src='../addons/bsht_tbk/res/images/androidcopy.png'></a>";
            }
        } else {
            html += "<a href='javascript:;' class='taokao'>" + tip + "</a>";
        }

        html += "</div>";
        html += "</div>";
        popw.innerHTML = html;
        document.body.appendChild(frag);
        canclepopw();

    }
    //$(".popwtitle").html(title);
    $(".popwcontent").html("<div id='copy_key_ios'>" + content + "</div>" + "<textarea class='copybox' id='copy_key_android'>" + content + "</textarea>");
    pop = document.querySelector(".popw");
    pop.style.display = "-webkit-box";
    $(".popwbox").addClass("popwboxshow");
    $(".copybox").on("input", function () {
        $(this).val(content);
    });

    //个人中心伙伴页面区分
    if($(".partnerwx").length < 1) {
        selection()
    } else {
        $(".copybox").hide();
    }

}


/*取消*/
function canclepopw() {
    $(".popwcancel,.popwbg,.popwcomfirm").click(function () {
        $(".popwbox").removeClass("popwboxshow");
        $(".popw").remove();
    })
}



/*悬浮提示框*/
function userAction(name, content, headerportrait) {
    var act;
    if (!document.querySelector(".useract")) {
        var useract = document.createElement("div");
        document.body.appendChild(useract);
        useract.className = "useract";

    }
    act = document.querySelector(".useract");
    act.innerHTML = "<img src='" + headerportrait + "'>" + name + ":" + content;
    act.classList.add("useractshow");
}


/*掉微信图集*/
function openWXimg() {

    $(".pjimg").each(function (index) {
        var imgsObj = $(this).find("div");
        var imgs = new Array();
        for (var i = 0; i < imgsObj.size(); i++) {
            imgs.push(imgsObj.eq(i).attr('src'));
        }

        $(this).find("div").on('click', function () {
            WeixinJSBridge.invoke('imagePreview', {
                'current': $(this).attr('src'),
                'urls': imgs
            });
        });
    })

}

function selection() {
    if (isIos()) {
        $("#copy_key_ios").css("display", "block");
        $("#copy_key_android").css("display", "none");
    } else {
        $("#copy_key_ios").css({
            "display": "block",
            opacity: 0,
            position: "relative",
            "z-index": 1
        });
        $("#copy_key_android").height($("#copy_key_ios").height() + "px");
        $("#copy_key_ios").hide();

    }
    document.addEventListener("selectionchange", function (e) {
        if (window.getSelection().anchorNode.parentNode.id == 'copy_key_ios' || window.getSelection().anchorNode.id == 'copy_key_ios') {
            var key = document.getElementById('copy_key_ios');
            window.getSelection().selectAllChildren(key);
        }
    }, false);

}

/*
window.addEventListener("scroll", function () {
    imgScrollIndex = 0;
    scrollLoadingImg(null, document.documentElement.clientHeight);
}, false);


//延时监听
/*setTimeout(function () {
    //监听物理返回按钮
    window.addEventListener("popstate", function (e) {
        $(".close").click();
        $(".close").hide();
        $("#menu").show();
    }, false);

}, 300);
/**
 * [pushHistory 写入空白历史记录]
 * @author 邱先生
 * @copyright 烟火里的尘埃
 * @version [V1.0版本]
 * @date 2016-07-30
 * @return {[type]} [description]
 */
/*function pushHistory() {
    var state = {
        title: "title",
        url: "#"
    };
    window.history.pushState(state, "title", "#");
}

*/

    